package com.xmkj.bearbiz.member;

import android.content.Intent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.common.BearBean.SomeMemberInfoBean;
import com.common.BearMethods.GetMemberDataMethods;
import com.common.cons.Constans;
import com.common.mvp.BaseMvpActivity;
import com.common.mvp.BasePresenter;
import com.common.retrofit.subscriber.CommonSubscriber;
import com.common.retrofit.subscriber.SubscriberListener;
import com.common.utils.SPUtils;
import com.xmkj.bearbiz.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MemberInfoDetailAcitivity extends BaseMvpActivity {
    public static final String DEPTCODE = "DEPTCODE";
    public static final String VIPCARDID = "VIPCARDID";
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_state)
    TextView tvState;
    @BindView(R.id.tv_age)
    TextView tvAge;
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    @BindView(R.id.tv_regeter_time)
    TextView tvRegeterTime;
    @BindView(R.id.tv_consume_count)
    TextView tvConsumeCount;
    @BindView(R.id.tv_order_count)
    TextView tvOrderCount;
    @BindView(R.id.tv_chuxu)
    TextView tvChuxu;
    @BindView(R.id.tv_jifen_can_used)
    TextView tvJifenCanUsed;
    @BindView(R.id.tv_consume_jian)
    TextView tvConsumeJian;
    @BindView(R.id.tv_consume_times)
    TextView tvConsumeTimes;
    @BindView(R.id.tv_share_person)
    TextView tvSharePerson;
    @BindView(R.id.tv_ke_price)
    TextView tvKePrice;
    @BindView(R.id.tv_jian_price)
    TextView tvJianPrice;
    @BindView(R.id.tv_rate)
    TextView tvRate;
    @BindView(R.id.tv_consume_date)
    TextView tvConsumeDate;
    @BindView(R.id.tv_consume_times_year)
    TextView tvConsumeTimesYear;
    @BindView(R.id.tv_compile)
    TextView tvCompile;
    @BindView(R.id.ll_order)
    LinearLayout llOrder;
    @BindView(R.id.ll_chuzhi)
    LinearLayout llChuzhi;
    @BindView(R.id.ll_jifen)
    LinearLayout llJifen;
    private String deptcode;
    private String vipcarid;

    @Override
    protected BasePresenter createPresenterInstance() {
        return null;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_member_info;
    }

    @Override
    protected void onViewCreated() {

    }

    @Override
    protected void doLogicFunc() {
        attachClickListener(llChuzhi);
        attachClickListener(llJifen);
        attachClickListener(llOrder);
        attachClickListener(tvCompile);
        deptcode = getIntent().getStringExtra(DEPTCODE);
        vipcarid = getIntent().getStringExtra(VIPCARDID);
        getData();

    }

    private void getData() {
        showProgressingDialog();
        CommonSubscriber<SomeMemberInfoBean> subscriber = new CommonSubscriber<>(new SubscriberListener() {
            @Override
            public void onNext(Object o) {
                dismissProgressDialog();
                SomeMemberInfoBean bean = (SomeMemberInfoBean) o;

                if(bean.is_restricted==1){
                    tvState.setVisibility(View.VISIBLE);
                }else {
                    tvState.setVisibility(View.GONE);
                }
                deptcode = bean.deptcode;
                tvName.setText(bean.nick_name);
                tvAge.setText("年龄："+bean.age);
                tvPhone.setText("手机号："+bean.mobile_phone);
                tvRegeterTime.setText("注册时间："+bean.input_date);
                tvConsumeCount.setText(bean.sale_money);
                tvOrderCount.setText(bean.all_sale);
                tvChuxu.setText(bean.ss_money+"");
                tvJifenCanUsed.setText(bean.point);
                tvConsumeJian.setText("消费件数               "+bean.sale_amount+"件");
                tvConsumeJian.setText("消费次数               "+bean.sale_num+"次");
                tvConsumeJian.setText("分享人数               "+bean.share_num+"人");
                tvConsumeJian.setText("客单价               "+bean.ke_unit+"");
                tvConsumeJian.setText("件单价               "+bean.jian_unit+"");
                tvConsumeJian.setText("连带率               "+bean.joint_rate+"");
                tvConsumeJian.setText("最近消费时间               "+bean.last_paydate+"");
                tvConsumeJian.setText("本年消费次数               "+bean.pay_num+"");


            }

            @Override
            public void onError(String e, int code) {
                dismissProgressDialog();
                showToastMsg(e);
            }
        });

//        jpushid = JPushInterface.getRegistrationID(this);
        GetMemberDataMethods.getInstance().vipUserInfo(subscriber, SPUtils.getShareInt(Constans.UID) + "", SPUtils.getShareString(Constans.HASHID), vipcarid);
        rxManager.add(subscriber);
    }

    @Override
    protected void onViewClicked(View view) {
        if (view.getId() == llChuzhi.getId()) {
            Intent intent = new Intent(context, ChuJiOrderListActivity.class);
            intent.putExtra(ChuJiOrderListActivity.TYPE, 2);
            startActivity(intent);
        } else if (llJifen.getId() == view.getId()) {
            Intent intent = new Intent(context, ChuJiOrderListActivity.class);
            intent.putExtra(ChuJiOrderListActivity.TYPE, 3);
            intent.putExtra(ChuJiOrderListActivity.VIPCARDID,vipcarid);
            intent.putExtra(ChuJiOrderListActivity.DEPTCODE,deptcode);
            startActivity(intent);
        } else if (llOrder.getId() == view.getId()) {
            Intent intent = new Intent(context, ChuJiOrderListActivity.class);
            intent.putExtra(ChuJiOrderListActivity.TYPE, 1);
            startActivity(intent);
        } else if (tvCompile.getId() == view.getId()) {
            Intent intent = new Intent(context, ModifyPersonInfoAcitivity.class);
            intent.putExtra(ModifyPersonInfoAcitivity.DEPTCODE,deptcode);
            intent.putExtra(ModifyPersonInfoAcitivity.VIPCARDID,vipcarid);
            startActivity(intent);
        }
    }

    @Override
    protected void setNavigation() {
        setNavigationBack("会员信息详情");
    }


    @Override
    public void bindKnife() {
        ButterKnife.bind(this);
    }


}
